package org.osforce.platform.service.impl;

import org.apache.commons.lang.StringUtils;
import org.osforce.platform.dao.IUserDao;
import org.osforce.platform.entity.User;
import org.osforce.platform.service.IUserService;
import org.osforce.platform.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 * @author gavin
 * 
 */
@Transactional
@Service("userService")
public class UserService implements IUserService{
	@Autowired
	private IUserDao userDao;

	public UserService(){
	}

	public User loginUser(User user){
		User registeredUser = this.userDao.findByUserName(user.getUserName());
		if(user!=null&&StringUtils.equals(
				user.getPassWord(),registeredUser.getPassWord())){
			return user;
		}
		return null;
	}
	
	public void registerUser(User user){
		this.userDao.save(user);
	}
	
	public Page<User> listUserByPage(Page<User> page){
		return userDao.findAllByPage(page);
	}
	
}
